﻿Imports System
Imports System.IO.Ports
Imports System.Windows.Forms.DataVisualization.Charting

Public Class frmMain
    Dim AD(16) As Integer

    Delegate Sub RecieveRefreshMethodDelegate(ByVal [text] As String) '声明委托
    Dim RecieveRefresh As New RecieveRefreshMethodDelegate(AddressOf RecieveRefreshMethod) '定义一个委托实例


    Sub RecieveRefreshMethod(ByVal str As String) '定义一个实例方法
        ShowRecieveData(str)
    End Sub
    Private Sub ShowRecieveData(ByVal str As String)
        On Error GoTo Err
        TextBoxRecieve.Text += str
        Exit Sub
Err:    MsgBox("数据接收或显示错误！" + vbNewLine + ErrorToString())
    End Sub

    Private Sub SerialPortInit()
        '串口设置GUI初始化
        ' Dim I As Integer
        '        ComboBoxPortName.BeginUpdate()
        '      For I = 1 To 50
        '      ComboBoxPortName.Items.Add("COM" + I.ToString)
        ' Next 
        Dim ports As String() = SerialPort.GetPortNames() '必须用命名空间，用SerialPort,获取计算机的有效串口
        Dim port As String
        For Each port In ports
            ComboBoxPortName.Items.Add(port) '向combobox中添加项
        Next port
        ComboBoxPortName.EndUpdate()
        'ComboBoxPortName.SelectedIndex = 0
        ComboBoxBaudRate.SelectedIndex = 11
        SerialPort.Encoding = System.Text.Encoding.Default
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SerialPortInit()
        ButtonOpenClose_Click(Nothing, Nothing)
        Dim minValue, maxValue As DateTime
        minValue = DateTime.Now
        maxValue = minValue.AddSeconds(600)

        chart1.ChartAreas.Clear()
        Dim ChartAreas1 As New ChartArea("Defult")    '定义新的ChartArea
        chart1.ChartAreas.Add(ChartAreas1)
        chart1.ChartAreas(0).AxisX.Title = "Time /s"   '设置ChartArea里坐标轴标题
        chart1.ChartAreas(0).AxisY.Title = "Slope"
        chart1.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        chart1.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        chart1.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        chart1.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        chart1.ChartAreas(0).AxisY.Maximum = 2500
        chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色

        chart1.Series.Clear()
        Dim series1 As New Series("slope0")
        chart1.Series.Add(series1)
        series1.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series1.BorderWidth = 1
        series1.Color = Color.Green
        series1.XValueType = ChartValueType.Time

        Dim series2 As New Series("slope1")
        chart1.Series.Add(series2)
        series2.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series2.BorderWidth = 1
        series2.Color = Color.Red
        series2.XValueType = ChartValueType.Time

        Dim series3 As New Series("slope2")
        chart1.Series.Add(series3)
        series3.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series3.BorderWidth = 1
        series3.Color = Color.Black
        series3.XValueType = ChartValueType.Time

        Dim series4 As New Series("slope3")
        chart1.Series.Add(series4)
        series4.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series4.BorderWidth = 1
        series4.Color = Color.AliceBlue
        series4.XValueType = ChartValueType.Time

        Dim series5 As New Series("slope4")
        chart1.Series.Add(series5)
        series5.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series5.BorderWidth = 1
        series5.Color = Color.AntiqueWhite
        series5.XValueType = ChartValueType.Time

        Dim series6 As New Series("slope5")
        chart1.Series.Add(series6)
        series6.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series6.BorderWidth = 1
        series6.Color = Color.Aqua
        series6.XValueType = ChartValueType.Time

        Dim series7 As New Series("slope6")
        chart1.Series.Add(series7)
        series7.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series7.BorderWidth = 1
        series7.Color = Color.Aquamarine
        series7.XValueType = ChartValueType.Time

        Dim series8 As New Series("slope7")
        chart1.Series.Add(series8)
        series8.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series8.BorderWidth = 1
        series8.Color = Color.Azure
        series8.XValueType = ChartValueType.Time

        Dim series9 As New Series("slope8")
        chart1.Series.Add(series9)
        series9.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series9.BorderWidth = 1
        series9.Color = Color.Azure
        series9.XValueType = ChartValueType.Time

        Dim series10 As New Series("slope9")
        chart1.Series.Add(series10)
        series10.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series10.BorderWidth = 1
        series10.Color = Color.Beige
        series10.XValueType = ChartValueType.Time

        Dim series11 As New Series("slope10")
        chart1.Series.Add(series11)
        series11.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series11.BorderWidth = 1
        series11.Color = Color.Bisque
        series11.XValueType = ChartValueType.Time

        Dim series12 As New Series("slope11")
        chart1.Series.Add(series12)
        series12.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series12.BorderWidth = 1
        series12.Color = Color.BlanchedAlmond
        series12.XValueType = ChartValueType.Time



        Chart2.ChartAreas.Clear()
        Dim ChartAreas2 As New ChartArea("Defult")    '定义新的ChartArea
        Chart2.ChartAreas.Add(ChartAreas2)
        Chart2.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart2.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart2.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart2.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart2.ChartAreas(0).AxisY.Maximum = 4096
        Chart2.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart2.Series.Clear()
        Dim series17 As New Series("AD0")
        Chart2.Series.Add(series17)
        series17.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series17.BorderWidth = 1
        series17.Color = Color.Red
        series17.XValueType = ChartValueType.Time
        Dim series40 As New Series("slope0")
        Chart2.Series.Add(series40)
        With series40
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With


        Chart3.ChartAreas.Clear()
        Dim ChartAreas3 As New ChartArea("Defult")    '定义新的ChartArea
        Chart3.ChartAreas.Add(ChartAreas3)
        Chart3.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart3.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart3.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart3.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart3.ChartAreas(0).AxisY.Maximum = 4096
        Chart3.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart3.Series.Clear()
        Dim series18 As New Series("AD1")
        Chart3.Series.Add(series18)
        series18.ChartType = SeriesChartType.Line '设置Series的绘图类型
        series18.BorderWidth = 1
        series18.Color = Color.Red
        series18.XValueType = ChartValueType.Time
        Dim series41 As New Series("slope1")
        Chart3.Series.Add(series41)
        With series41
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With

        Chart4.ChartAreas.Clear()
        Dim ChartAreas4 As New ChartArea("Defult")    '定义新的ChartArea
        Chart4.ChartAreas.Add(ChartAreas4)
        Chart4.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart4.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart4.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart4.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart4.ChartAreas(0).AxisY.Maximum = 4096
        Chart4.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart4.Series.Clear()
        Dim series19 As New Series("AD2")
        Chart4.Series.Add(series19)
        With series19
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series42 As New Series("slope2")
        Chart4.Series.Add(series42)
        With series42
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With

        Chart5.ChartAreas.Clear()
        Dim ChartAreas5 As New ChartArea("Defult")    '定义新的ChartArea
        Chart5.ChartAreas.Add(ChartAreas5)
        Chart5.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart5.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart5.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart5.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart5.ChartAreas(0).AxisY.Maximum = 4096
        Chart5.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart5.Series.Clear()
        Dim series20 As New Series("AD3")
        Chart5.Series.Add(series20)
        With series20
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series43 As New Series("slope3")
        Chart5.Series.Add(series43)
        With series43
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With

        Chart6.ChartAreas.Clear()
        Dim ChartAreas6 As New ChartArea("Defult")    '定义新的ChartArea
        Chart6.ChartAreas.Add(ChartAreas6)
        Chart6.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart6.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart6.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart6.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart6.ChartAreas(0).AxisY.Maximum = 4096
        Chart6.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart6.Series.Clear()
        Dim series21 As New Series("AD4")
        Chart6.Series.Add(series21)
        With series21
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series44 As New Series("slope4")
        Chart6.Series.Add(series44)
        With series44
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With


        Chart7.ChartAreas.Clear()
        Dim ChartAreas7 As New ChartArea("Defult")    '定义新的ChartArea
        Chart7.ChartAreas.Add(ChartAreas7)
        Chart7.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart7.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart7.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart7.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart7.ChartAreas(0).AxisY.Maximum = 4096
        Chart7.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart7.Series.Clear()
        Dim series22 As New Series("AD5")
        Chart7.Series.Add(series22)
        With series22
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series45 As New Series("slope5")
        Chart7.Series.Add(series45)
        With series45
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With


        Chart8.ChartAreas.Clear()
        Dim ChartAreas8 As New ChartArea("Defult")    '定义新的ChartArea
        Chart8.ChartAreas.Add(ChartAreas8)
        Chart8.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart8.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart8.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart8.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart8.ChartAreas(0).AxisY.Maximum = 4096
        Chart8.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart8.Series.Clear()
        Dim series23 As New Series("AD6")
        Chart8.Series.Add(series23)
        With series23
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series46 As New Series("slope6")
        Chart8.Series.Add(series46)
        With series46
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With



        Chart9.ChartAreas.Clear()
        Dim ChartAreas9 As New ChartArea("Defult")    '定义新的ChartArea
        Chart9.ChartAreas.Add(ChartAreas9)
        Chart9.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart9.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart9.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart9.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart9.ChartAreas(0).AxisY.Maximum = 4096
        Chart9.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart9.Series.Clear()
        Dim series24 As New Series("AD7")
        Chart9.Series.Add(series24)
        With series24
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series47 As New Series("slope7")
        Chart9.Series.Add(series47)
        With series47
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With


        Chart10.ChartAreas.Clear()
        Dim ChartAreas10 As New ChartArea("Defult")    '定义新的ChartArea
        Chart10.ChartAreas.Add(ChartAreas10)
        Chart10.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart10.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart10.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart10.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart10.ChartAreas(0).AxisY.Maximum = 4096
        Chart10.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart10.Series.Clear()
        Dim series25 As New Series("AD8")
        Chart10.Series.Add(series25)
        With series25
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series48 As New Series("slope8")
        Chart10.Series.Add(series48)
        With series48
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With


        Chart11.ChartAreas.Clear()
        Dim ChartAreas11 As New ChartArea("Defult")    '定义新的ChartArea
        Chart11.ChartAreas.Add(ChartAreas11)
        Chart11.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart11.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart11.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart11.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart11.ChartAreas(0).AxisY.Maximum = 4096
        Chart11.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart11.Series.Clear()
        Dim series26 As New Series("AD9")
        Chart11.Series.Add(series26)
        With series26
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series49 As New Series("slope9")
        Chart11.Series.Add(series49)
        With series49
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With


        Chart12.ChartAreas.Clear()
        Dim ChartAreas12 As New ChartArea("Defult")    '定义新的ChartArea
        Chart12.ChartAreas.Add(ChartAreas12)
        Chart12.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart12.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart12.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart12.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart12.ChartAreas(0).AxisY.Maximum = 4096
        Chart12.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart12.Series.Clear()
        Dim series27 As New Series("AD10")
        Chart12.Series.Add(series27)
        With series27
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series50 As New Series("slope10")
        Chart12.Series.Add(series50)
        With series50
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With


        Chart13.ChartAreas.Clear()
        Dim ChartAreas13 As New ChartArea("Defult")    '定义新的ChartArea
        Chart13.ChartAreas.Add(ChartAreas13)
        Chart13.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart13.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart13.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart13.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart13.ChartAreas(0).AxisY.Maximum = 4096
        Chart13.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart13.Series.Clear()
        Dim series28 As New Series("AD11")
        Chart13.Series.Add(series28)
        With series28
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With
        Dim series51 As New Series("slope11")
        Chart13.Series.Add(series51)
        With series51
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Blue
        End With


        Chart14.ChartAreas.Clear()
        Dim ChartAreas14 As New ChartArea("Defult")    '定义新的ChartArea
        Chart14.ChartAreas.Add(ChartAreas14)
        Chart14.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart14.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart14.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart14.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart14.ChartAreas(0).AxisY.Maximum = 4096
        Chart14.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray
        Chart14.Series.Clear()
        Dim series29 As New Series("AD12")
        Chart14.Series.Add(series29)
        With series29
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With


        Chart15.ChartAreas.Clear()
        Dim ChartAreas15 As New ChartArea("Defult")    '定义新的ChartArea
        Chart15.ChartAreas.Add(ChartAreas15)
        Chart15.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart15.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart15.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart15.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart15.ChartAreas(0).AxisY.Maximum = 5000
        Chart15.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray
        Chart15.Series.Clear()
        Dim series30 As New Series("AD13")
        Chart15.Series.Add(series30)
        With series30
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With


        Chart16.ChartAreas.Clear()
        Dim ChartAreas16 As New ChartArea("Defult")    '定义新的ChartArea
        Chart16.ChartAreas.Add(ChartAreas16)
        Chart16.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart16.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart16.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart16.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart16.ChartAreas(0).AxisY.Maximum = 4096
        Chart16.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart16.Series.Clear()
        Dim series31 As New Series("AD14")
        Chart16.Series.Add(series31)
        With series31
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With


        Chart17.ChartAreas.Clear()
        Dim ChartAreas17 As New ChartArea("Defult")    '定义新的ChartArea
        Chart17.ChartAreas.Add(ChartAreas17)
        Chart17.ChartAreas(0).AxisX.Minimum = minValue.ToOADate() 'x轴幅度
        Chart17.ChartAreas(0).AxisX.Maximum = maxValue.ToOADate()
        Chart17.ChartAreas(0).AxisX.MajorGrid.LineColor = Color.LightGray 'x轴颜色
        Chart17.ChartAreas(0).AxisY.Minimum = 0 'y轴幅度
        Chart17.ChartAreas(0).AxisY.Maximum = 4096
        Chart17.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.LightGray 'y轴颜色
        Chart17.Series.Clear()
        Dim series32 As New Series("AD15")
        Chart17.Series.Add(series32)
        With series32
            .XValueType = ChartValueType.Time
            .ChartType = SeriesChartType.Line
            .BorderWidth = 1
            .Color = Color.Red
        End With


        chart1.Legends(0).Docking = Docking.Right            '取消图例显示
        Chart2.Legends(0).Docking = Docking.Right
        Chart3.Legends(0).Docking = Docking.Right
        Chart4.Legends(0).Docking = Docking.Right
        Chart5.Legends(0).Docking = Docking.Right
        Chart9.Legends(0).Docking = Docking.Right
        Chart8.Legends(0).Docking = Docking.Right
        Chart7.Legends(0).Docking = Docking.Right
        Chart6.Legends(0).Docking = Docking.Right
        Chart13.Legends(0).Docking = Docking.Right
        Chart12.Legends(0).Docking = Docking.Right
        Chart11.Legends(0).Docking = Docking.Right
        Chart10.Legends(0).Docking = Docking.Right
        Chart17.Legends(0).Docking = Docking.Right
        Chart16.Legends(0).Docking = Docking.Right
        Chart15.Legends(0).Docking = Docking.Right
        Chart14.Legends(0).Docking = Docking.Right
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim rand As New Random
        Dim curent_time As DateTime
        curent_time = DateTime.Now

        If SerialPort.IsOpen = True Then

            chart1.Series("slope0").Points.AddXY(curent_time.ToOADate(), Val(slope0.Text))   '为这个Series加数据点
            If chart1.Series("slope0").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope0").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope0").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope0").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope1").Points.AddXY(curent_time.ToOADate(), Val(slope1.Text))    '为这个Series加数据点
            If chart1.Series("slope1").Points.Count >= 595 Then   '采样点大于295个后
                chart1.Series("slope1").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope1").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope1").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope2").Points.AddXY(curent_time.ToOADate(), Val(slope2.Text))    '为这个Series加数据点
            If chart1.Series("slope2").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope2").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope2").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope2").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope3").Points.AddXY(curent_time.ToOADate(), Val(slope3.Text))    '为这个Series加数据点
            If chart1.Series("slope3").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope3").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope3").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope3").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope4").Points.AddXY(curent_time.ToOADate(), Val(slope4.Text))    '为这个Series加数据点
            If chart1.Series("slope4").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope4").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope4").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope4").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope5").Points.AddXY(curent_time.ToOADate(), Val(slope5.Text))    '为这个Series加数据点
            If chart1.Series("slope5").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope5").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope5").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope5").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope6").Points.AddXY(curent_time.ToOADate(), Val(slope6.Text))    '为这个Series加数据点
            If chart1.Series("slope6").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope6").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope6").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope6").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope7").Points.AddXY(curent_time.ToOADate(), Val(slope7.Text))    '为这个Series加数据点
            If chart1.Series("slope7").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope7").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope7").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope7").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope8").Points.AddXY(curent_time.ToOADate(), Val(slope8.Text))    '为这个Series加数据点
            If chart1.Series("slope8").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope8").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope8").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope8").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope9").Points.AddXY(curent_time.ToOADate(), Val(slope9.Text))    '为这个Series加数据点
            If chart1.Series("slope9").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope9").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope9").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope9").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope10").Points.AddXY(curent_time.ToOADate(), Val(slope10.Text))    '为这个Series加数据点
            If chart1.Series("slope10").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope10").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope10").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope10").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            chart1.Series("slope11").Points.AddXY(curent_time.ToOADate(), Val(slope11.Text))    '为这个Series加数据点
            If chart1.Series("slope11").Points.Count >= 595 Then   '采样点大于595个后
                chart1.Series("slope11").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In chart1.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = chart1.Series("slope11").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(chart1.Series("slope11").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If



            Chart2.Series("AD0").Points.AddXY(curent_time.ToOADate(), Val(AD0.Text))   '为这个Series加数据点
            If Chart2.Series("AD0").Points.Count >= 595 Then   '采样点大于595个后
                Chart2.Series("AD0").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart2.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart2.Series("AD0").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart2.Series("AD0").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart2.Series("slope0").Points.AddXY(curent_time.ToOADate(), Val(slope0.Text))   '为这个Series加数据点
            If Chart2.Series("slope0").Points.Count >= 595 Then   '采样点大于595个后
                Chart2.Series("slope0").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart2.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart2.Series("slope0").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart2.Series("slope0").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If


            Chart3.Series("AD1").Points.AddXY(curent_time.ToOADate(), Val(AD1.Text))    '为这个Series加数据点
            If Chart3.Series("AD1").Points.Count >= 595 Then   '采样点大于595个后
                Chart3.Series("AD1").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart3.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart3.Series("AD1").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart3.Series("AD1").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart3.Series("slope1").Points.AddXY(curent_time.ToOADate(), Val(slope1.Text))    '为这个Series加数据点
            If Chart3.Series("slope1").Points.Count >= 595 Then   '采样点大于595个后
                Chart3.Series("slope1").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart3.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart3.Series("slope1").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart3.Series("slope1").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart4.Series("AD2").Points.AddXY(curent_time.ToOADate(), Val(AD2.Text))    '为这个Series加数据点
            If Chart4.Series("AD2").Points.Count >= 595 Then   '采样点大于595个后
                Chart4.Series("AD2").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart4.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart4.Series("AD2").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart4.Series("AD2").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart4.Series("slope2").Points.AddXY(curent_time.ToOADate(), Val(slope2.Text))    '为这个Series加数据点
            If Chart4.Series("slope2").Points.Count >= 595 Then   '采样点大于595个后
                Chart4.Series("slope2").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart4.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart4.Series("slope2").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart4.Series("slope2").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart5.Series("AD3").Points.AddXY(curent_time.ToOADate(), Val(AD3.Text))    '为这个Series加数据点
            If Chart5.Series("AD3").Points.Count >= 595 Then   '采样点大于595个后
                Chart5.Series("AD3").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart5.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart5.Series("AD3").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart5.Series("AD3").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart5.Series("slope3").Points.AddXY(curent_time.ToOADate(), Val(slope3.Text))    '为这个Series加数据点
            If Chart5.Series("slope3").Points.Count >= 595 Then   '采样点大于595个后
                Chart5.Series("slope3").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart5.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart5.Series("slope3").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart5.Series("slope3").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart6.Series("AD4").Points.AddXY(curent_time.ToOADate(), Val(AD4.Text))    '为这个Series加数据点
            If Chart6.Series("AD4").Points.Count >= 595 Then   '采样点大于595个后
                Chart6.Series("AD4").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart6.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart6.Series("AD4").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart6.Series("AD4").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart6.Series("slope4").Points.AddXY(curent_time.ToOADate(), Val(slope4.Text))    '为这个Series加数据点
            If Chart6.Series("slope4").Points.Count >= 595 Then   '采样点大于595个后
                Chart6.Series("slope4").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart6.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart6.Series("slope4").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart6.Series("slope4").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart7.Series("AD5").Points.AddXY(curent_time.ToOADate(), Val(AD5.Text))    '为这个Series加数据点
            If Chart7.Series("AD5").Points.Count >= 595 Then   '采样点大于595个后
                Chart7.Series("AD5").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart7.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart7.Series("AD5").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart7.Series("AD5").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart7.Series("slope5").Points.AddXY(curent_time.ToOADate(), Val(slope5.Text))    '为这个Series加数据点
            If Chart7.Series("slope5").Points.Count >= 595 Then   '采样点大于595个后
                Chart7.Series("slope5").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart7.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart7.Series("slope5").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart7.Series("slope5").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart8.Series("AD6").Points.AddXY(curent_time.ToOADate(), Val(AD6.Text))    '为这个Series加数据点
            If Chart8.Series("AD6").Points.Count >= 595 Then   '采样点大于595个后
                Chart8.Series("AD6").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart8.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart8.Series("AD6").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart8.Series("AD6").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart8.Series("slope6").Points.AddXY(curent_time.ToOADate(), Val(slope6.Text))    '为这个Series加数据点
            If Chart8.Series("slope6").Points.Count >= 595 Then   '采样点大于595个后
                Chart8.Series("slope6").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart8.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart8.Series("slope6").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart8.Series("slope6").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart9.Series("AD7").Points.AddXY(curent_time.ToOADate(), Val(AD7.Text))    '为这个Series加数据点
            If Chart9.Series("AD7").Points.Count >= 595 Then   '采样点大于595个后
                Chart9.Series("AD7").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart9.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart9.Series("AD7").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart9.Series("AD7").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart9.Series("slope7").Points.AddXY(curent_time.ToOADate(), Val(slope7.Text))    '为这个Series加数据点
            If Chart9.Series("slope7").Points.Count >= 595 Then   '采样点大于595个后
                Chart9.Series("slope7").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart9.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart9.Series("slope7").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart9.Series("slope7").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart10.Series("AD8").Points.AddXY(curent_time.ToOADate(), Val(AD8.Text))    '为这个Series加数据点
            If Chart10.Series("AD8").Points.Count >= 595 Then   '采样点大于595个后
                Chart10.Series("AD8").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart10.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart10.Series("AD8").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart10.Series("AD8").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart10.Series("slope8").Points.AddXY(curent_time.ToOADate(), Val(slope8.Text))    '为这个Series加数据点
            If Chart10.Series("slope8").Points.Count >= 595 Then   '采样点大于595个后
                Chart10.Series("slope8").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart10.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart10.Series("slope8").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart10.Series("slope8").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart11.Series("AD9").Points.AddXY(curent_time.ToOADate(), Val(AD9.Text))    '为这个Series加数据点
            If Chart11.Series("AD9").Points.Count >= 595 Then   '采样点大于595个后
                Chart11.Series("AD9").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart11.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart11.Series("AD9").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart11.Series("AD9").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart11.Series("slope9").Points.AddXY(curent_time.ToOADate(), Val(slope9.Text))    '为这个Series加数据点
            If Chart11.Series("slope9").Points.Count >= 595 Then   '采样点大于595个后
                Chart11.Series("slope9").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart11.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart11.Series("slope9").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart11.Series("slope9").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart12.Series("AD10").Points.AddXY(curent_time.ToOADate(), Val(AD10.Text))    '为这个Series加数据点
            If Chart12.Series("AD10").Points.Count >= 595 Then   '采样点大于595个后
                Chart12.Series("AD10").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart12.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart12.Series("AD10").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart12.Series("AD10").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart12.Series("slope10").Points.AddXY(curent_time.ToOADate(), Val(slope10.Text))    '为这个Series加数据点
            If Chart12.Series("slope10").Points.Count >= 595 Then   '采样点大于595个后
                Chart12.Series("slope10").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart12.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart12.Series("slope10").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart12.Series("slope10").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart13.Series("AD11").Points.AddXY(curent_time.ToOADate(), Val(AD11.Text))    '为这个Series加数据点
            If Chart13.Series("AD11").Points.Count >= 595 Then   '采样点大于595个后
                Chart13.Series("AD11").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart13.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart13.Series("AD11").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart13.Series("AD11").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If
            Chart13.Series("slope11").Points.AddXY(curent_time.ToOADate(), Val(slope11.Text))    '为这个Series加数据点
            If Chart13.Series("slope11").Points.Count >= 595 Then   '采样点大于595个后
                Chart13.Series("slope11").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart13.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart13.Series("slope11").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart13.Series("slope11").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart14.Series("AD12").Points.AddXY(curent_time.ToOADate(), Val(AD12.Text))    '为这个Series加数据点
            If Chart14.Series("AD12").Points.Count >= 595 Then   '采样点大于595个后
                Chart14.Series("AD12").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart14.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart14.Series("AD12").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart14.Series("AD12").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart15.Series("AD13").Points.AddXY(curent_time.ToOADate(), Val(AD13.Text))    '为这个Series加数据点
            If Chart15.Series("AD13").Points.Count >= 595 Then   '采样点大于595个后
                Chart15.Series("AD13").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart15.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart15.Series("AD13").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart15.Series("AD13").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If

            Chart16.Series("AD14").Points.AddXY(curent_time.ToOADate(), Val(AD14.Text))    '为这个Series加数据点
            If Chart16.Series("AD14").Points.Count >= 595 Then   '采样点大于595个后
                Chart16.Series("AD14").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart16.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart16.Series("AD14").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart16.Series("AD14").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If


            Chart17.Series("AD15").Points.AddXY(curent_time.ToOADate(), Val(AD15.Text))    '为这个Series加数据点
            If Chart17.Series("AD15").Points.Count >= 595 Then   '采样点大于595个后
                Chart17.Series("AD15").Points.RemoveAt(0) '删除曲线头个数据
                Dim ptA As ChartArea
                For Each ptA In Chart17.ChartAreas      '更新坐标轴时间
                    ptA.AxisX.Minimum = Chart17.Series("AD15").Points(0).XValue
                    ptA.AxisX.Maximum = DateTime.FromOADate(Chart17.Series("AD15").Points(0).XValue).AddSeconds(100).ToOADate()
                Next
            End If


        End If

    End Sub

    Private Sub frmMain_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closing
        If SerialPort.IsOpen Then SerialPort.Close()
    End Sub

    Private Sub ComboBoxPortName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxPortName.SelectedIndexChanged
        If SerialPort.IsOpen = True Then
            ButtonOpenClose_Click(Nothing, Nothing)
            If SerialPort.IsOpen = False Then
                SerialPort.PortName = ComboBoxPortName.Text
                ButtonOpenClose_Click(Nothing, Nothing)
            End If
        Else
            SerialPort.PortName = ComboBoxPortName.Text
        End If
    End Sub

    Private Sub ComboBoxBaudRate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxBaudRate.SelectedIndexChanged
        SerialPort.BaudRate = Val(ComboBoxBaudRate.Text)
    End Sub



    Private Sub ButtonOpenClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOpenClose.Click
        On Error GoTo Err
        If ButtonOpenClose.Text = "打开串口(&O)" Then
            If SerialPort.IsOpen = True Then SerialPort.Close()
            SerialPort.Open()
            ButtonOpenClose.Text = "关闭串口(&O)"
            LabelCOMStatus.Text = "串口已打开"
            LabelCOMStatus.ForeColor = Color.Green
        Else

            If SerialPort.IsOpen = True Then SerialPort.Close()
            ButtonOpenClose.Text = "打开串口(&O)"
            LabelCOMStatus.Text = "串口已关闭"
            LabelCOMStatus.ForeColor = Color.Red
        End If
        Exit Sub

Err:    MsgBox("串口不存在或已被占用！" + vbNewLine + ErrorToString())

    End Sub



    Private Sub ButtonSendData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSendData.Click
        On Error GoTo Err
        Dim outDataBuf As String = TextBoxSend.Text
        If outDataBuf = "" Then Exit Sub
        If SerialPort.IsOpen = True Then
            '-------------文本发送--------------
            SerialPort.Write(outDataBuf)
        Else
            MsgBox("串口未打开，请先打开串口。")
        End If
        Exit Sub
Err:    MsgBox("数据输入或发送错误！" + vbNewLine + ErrorToString())

    End Sub

    Private Sub ButtonClearSendBuf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClearSendBuf.Click
        TextBoxSend.Text = ""
    End Sub

    Private Sub ButtonClearRecieveBuf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClearRecieveBuf.Click
        TextBoxRecieve.Text = ""
        AD0.Text = ""
        AD1.Text = ""
        AD2.Text = ""
        AD3.Text = ""
        AD4.Text = ""
        AD5.Text = ""
        AD6.Text = ""
        AD7.Text = ""
        AD8.Text = ""
        AD9.Text = ""
        AD10.Text = ""
        AD11.Text = ""
        AD12.Text = ""
        AD13.Text = ""
        AD14.Text = ""
        AD15.Text = ""
        slope0 .Text = " "
        slope1 .Text = " "
        slope2 .Text = ""
        slope3.Text = ""
        slope4 .Text = ""
        slope5.Text = ""
        slope6.Text = ""
        slope7.Text = ""
        slope8.Text = ""
        slope9.Text = ""
        slope10.Text = ""
        slope11.Text = ""
        slope12.Text = ""
        slope13.Text = ""
        slope14.Text = ""
        slope15.Text = ""
        data.Text = ""
        Sensor.Text = ""
    End Sub

    Private Sub TextBoxRecieve_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxRecieve.TextChanged
        TextBoxRecieve.SelectionStart = TextBoxRecieve.Text.Length  '获取或设置文本框中选定的文本起始点
        TextBoxRecieve.ScrollToCaret()                              '将控件的内容滚动到当前插入符号位置
    End Sub
    Private Sub TimerAutoSend_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ButtonSendData_Click(Nothing, Nothing)
    End Sub


    '触发接收事件
    Public Sub Sp_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
        Me.Invoke(New EventHandler(AddressOf Sp_Receiving)) '调用接收数据函数

    End Sub

    '接收数据
    Private Sub Sp_Receiving(ByVal sender As Object, ByVal e As EventArgs)
        Dim temp
        Try
            ' If SerialPort.BytesToRead > 0 Then
            Threading.Thread.Sleep(10) '延时20ms
            '-------------文本显示--------------
            Dim str As String
            str = SerialPort.ReadExisting        '在编码的基础上，读取port.serialport对象的流和输入缓冲区中所有立即可用的字节
            SerialPort.DiscardInBuffer()        '清除串行驱动程序的接收缓冲区的数据
            TextBoxRecieve.Invoke(RecieveRefresh, str)
            TextBoxRecieve.Text = str
            temp = Split(str)  '以“”分割字符串，装入temp数组
            If temp(0) = "a" Then
                AD0.Text = temp(1)
                AD1.Text = temp(2)
                AD2.Text = temp(3)
                AD3.Text = temp(4)
                AD4.Text = temp(5)
                AD5.Text = temp(6)
                AD6.Text = temp(7)
                AD7.Text = temp(8)
                AD8.Text = temp(9)
                AD9.Text = temp(10)
                AD10.Text = temp(11)
                AD11.Text = temp(12)
                AD12.Text = temp(13)
                AD13.Text = temp(14)
                AD14.Text = temp(15)
                AD15.Text = temp(16)
            End If
            If temp(0) = "s" Then
                slope0.Text = temp(1)
                If Val(temp(1)) > 700 Then
                    Sensor.Text = 1
                    data.Text = temp(1)
                End If
                slope1.Text = temp(2)
                If Val(temp(2)) > 700 Then
                    Sensor.Text = 2
                    data.Text = Val(temp(2))
                End If
                slope2.Text = temp(3)
                If Val(temp(3)) > 700 Then
                    Sensor.Text = 3
                    data.Text = Val(temp(3))
                End If
                slope3.Text = temp(4)
                If Val(temp(4)) > 700 Then
                    Sensor.Text = 4
                    data.Text = Val(temp(4))
                End If
                slope4.Text = temp(5)
                If Val(temp(5)) > 700 Then
                    Sensor.Text = 5
                    data.Text = Val(temp(5))
                End If
                slope5.Text = temp(6)
                If Val(temp(6)) > 700 Then
                    Sensor.Text = 6
                    data.Text = Val(temp(6))
                End If
                slope6.Text = temp(7)
                If Val(temp(7)) > 700 Then
                    Sensor.Text = 7
                    data.Text = Val(temp(7))
                End If
                slope7.Text = temp(8)
                If Val(temp(8)) > 700 Then
                    Sensor.Text = 8
                    data.Text = Val(temp(8))
                End If
                slope8.Text = temp(9)
                If Val(temp(9)) > 700 Then
                    Sensor.Text = 9
                    data.Text = Val(temp(9))
                End If
                slope9.Text = temp(10)
                If Val(temp(10)) > 700 Then
                    Sensor.Text = 10
                    data.Text = Val(temp(10))
                End If
                slope10.Text = temp(11)
                If Val(temp(11)) > 700 Then
                    Sensor.Text = 11
                    data.Text = Val(temp(11))
                End If
                slope11.Text = temp(12)
                If Val(temp(12)) > 700 Then
                    Sensor.Text = 12
                    data.Text = Val(temp(12))
                End If
            End If

            str = ""
        Catch ex As Exception
            ' MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ComboBoxPortName_Click(sender As Object, e As EventArgs) Handles ComboBoxPortName.Click
        ComboBoxPortName.Items.Clear()
        Dim ports As String() = SerialPort.GetPortNames() '必须用命名空间，用SerialPort,获取计算机的有效串口
        Dim port As String
        For Each port In ports
            ComboBoxPortName.Items.Add(port) '向combobox中添加项
        Next port
    End Sub

    Private Sub Chart8_Click(sender As Object, e As EventArgs) Handles Chart7.Click

    End Sub
End Class


